package com.yyjj.zixun.fragmnet;

import android.os.Bundle;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.vise.xsnow.http.mode.CacheMode;
import com.yyjj.zixun.R;
import com.yyjj.zixun.adapter.BTBNewsAdapter;
import com.yyjj.zixun.api.Api;
import com.yyjj.zixun.entity.BTBNewsEntity;

import java.util.ArrayList;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadFragment;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.entity.BaseTResp;


public class ZixunFragment extends BaseRefreshLoadFragment<BTBNewsEntity> {

    public static ZixunFragment newInstance() {
        Bundle args = new Bundle();
        ZixunFragment fragment = new ZixunFragment();
        fragment.setArguments(args);
        return fragment;
    }

//    @Override
//    public void setTitleBar(TitleBarView titleBar) {
//        titleBar.setTitleMainText("资讯");
//    }

    @Override
    public int getContentLayout() {
        return R.layout.zixun_fragment;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
    }

    @Override
    public BaseQuickAdapter<BTBNewsEntity, BaseViewHolder> getAdapter() {
        return new BTBNewsAdapter();
    }

    @Override
    public void loadData(int page) {
        ViseHttp.GET(Api.NETEASE_URL)
                .baseUrl(ApiConstant.BASE_URL)
                .addParam("type", "4")
                .setHttpCache(true)
                .cacheMode(CacheMode.FIRST_REMOTE)
                .request(new ACallback<BaseTResp<ArrayList<BTBNewsEntity>>>() {
                    @Override
                    public void onSuccess(BaseTResp<ArrayList<BTBNewsEntity>> data) {
                        if (data.code ==1){
                        if (data.data != null) {
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), data.data, null);
//                            mjiaoYiYuanAdapter.setNewData(data.data);
                        } else {
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), null, null);
                        }
                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
//                        FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), null, null);
                    }
                });
    }
}
